<template>
  <div id="course">
    <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
      <van-list v-model="loading" :finished="finished" finished-text="没有更多了" :immediate-check="false" @load="onLoad" offset="20">
        <ul>
          <li v-for="(ite,ind) in pagelist" :key="ind" @click="teacher(ite)">
            <img :src="ite.avatar" alt="">
            <div>
              <p>{{ite.real_name}}</p>
              <span>{{ite.introduction}}</span>
            </div>
          </li>
        </ul>
      </van-list>
    </van-pull-refresh>
  </div>
</template>
<script>
import { ke } from '@/api/user.js'
export default {
  data() {
    return {
      pagenu: {
        page: 1,
        limit: 2
      },
      pagelist: [],
      loading: false,
      finished: false,
      taol: 0,
      refreshing: false
    }
  },
  methods: {
    onRefresh() {
      this.finished = false

      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      this.loading = true
      this.onLoad()
    },
   async onLoad() {
        if (this.refreshing) {
          this.pagelist = []
          this.pagenu.page = 0
          this.refreshing = false
        }
        this.pagenu.page+=1
      await this.kelist()
        // 加载状态结束
        this.loading = false
        let oo = Math.ceil(this.taol / this.pagenu.limit)
        // 数据全部加载完成
        if (this.pagenu.page > oo) {
          this.finished = true
        }

    },
    async kelist() {
      let { data: data } = await ke(this.pagenu)
      console.log(data.data)
      this.taol = data.data.total
      if (this.pagelist) {
        this.pagelist = [...this.pagelist, ...data.data.list]
      } else {
        this.pagelist = data.data.list
      }
    },
    teacher(item) {
      this.$router.push('/tea_deatile?id=' + item.id)
    }
  },
  created() {
    this.kelist()
  }
}
</script>
<style lang="scss" scoped>
#course {
  height: 100%;
  background: #f7f8fa;
}
ul {
  padding: 0 15px;
  margin: 20px 0;
  li {
    width: 100%;
    height: 500px;
    box-sizing: border-box;
    background: white;
    border-radius: 10px;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    padding: 15px;
    img {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      margin-right: 10px;
    }
    div {
      p {
        font-size: 16px;
        margin-bottom: 5px;
      }
      span {
        color: #b7b7b7;
        font-size: 12px;
      }
    }
  }
}
</style>


